<?php

class ClsTracking extends ClsNaanalController
{
   public function __construct()
    {
        parent::__construct();
    } 
   function show_list() 
    {
        $this->mode='list';
        $arrWhere=array();$arrRequest=ClsNaanalRequest::getInstance();
        $arrWhere[]=array("field"=>"user_id","data"=>  ClsNaanalRequest::getInstance()->getData("user_id"));
        $fromDate=ClsNaanalRequest::getInstance()->getData("fromdate");
        $toDate=ClsNaanalRequest::getInstance()->getData("todate");
        $arrFromDate=explode("/",$fromDate);
        $arrToDate=explode("/",$toDate);
        $arrList=array();
        if(count($arrFromDate)===3 && count($arrToDate)===3)
        {
            $fromDateTime =  mktime(0, 0, 0, trim($arrFromDate[0]), trim($arrFromDate[1]), trim($arrFromDate[2]));
            $toDateTime = mktime(23, 59, 59, trim($arrToDate[0]), trim($arrToDate[1]), trim($arrToDate[2]));
            $arrWhere[]=array("field"=>"actiontime","condition"=>"between","data"=> $fromDateTime.",".$toDateTime);

            $arrRequestParam=array();
            $arrRequestParam["user_id"] = ClsNaanalRequest::getInstance()->getData("user_id");
            $arrRequestParam["fromdate"] = ClsNaanalRequest::getInstance()->getData("fromdate");
            $arrRequestParam["todate"] = ClsNaanalRequest::getInstance()->getData("todate");

            $arrList = $this->showList($arrWhere,array(),array(),$arrRequestParam);
            if($arrList["list"])
            foreach($arrList["list"] as $ind=>$list)
            {
                $arrList["list"][$ind]["actiontime"]=date("m/d/Y h:i:s",$list["actiontime"]);
            }
            return $arrList;
        }
        else
        {
            errMsg("Error in date input");
            $this->redirect="{$this->urlModuleParam}=tracking&{$this->urlActionParam}=create";
        }
    }   
   public function create()
    {
        $this->mode='create';
        $form=new ClsWTracking("tracking");
        $client_id=ClsNaanalSession::getInstance()->getPanelData("client_id");
        $arrUser=$form->get_user_lookup("name",array("field"=>"client_id","data"=>$client_id)); 
        $objHTML=ClsNaanalLibrary::getInstance("html");
        $objHTMLSelect=$objHTML->getHtmlSelect("user_id",$arrUser);   
        $objHTMLSelect->setParam("class","required");
        $user=$objHTMLSelect->render();
        
        return array('form'=>$form,'issubmit'=>false,"user"=>$user);
    }
    function edit() 
    {
        $this->form->loadObject($this->objNaanalRequest->getData('id'));
        $id=$this->objNaanalRequest->getData('id');
        $this->form->loadObject($id);
        return array("form"=>$this->form);
    } 
    /*function insert()
    {
        $arrRequest=$this->objNaanalRequest->getAll();
        //$this->form->set_name($arrRequest['name']);
        $userid=$arrRequest['user_id'];
        trace($this->form);
        $this->form->set_user_id($userid);
        $this->form->update();
        $pagevar=ClsConfig::$PAGINATION_VAR;
        $curpage=isset($arrRequest[$pagevar])?$arrRequest[$pagevar]:1;
        $this->redirect="page=tracking&action=list&{$pagevar}={$curpage}";
    }
      function update()
    {
        $arrRequest=$this->objNaanalRequest->getAll();
        $this->form->loadObject($arrRequest['id']);
        $this->form->set_name($arrRequest['name']);
        $userid=ClsNaanalSession::getInstance()->getLoginID();
        $this->form->set_user_id($userid);
        $this->form->set_actiontime($this->get_actiontime());
        $this->form->update();
        $pagevar=ClsConfig::$PAGINATION_VAR;
        $curpage=isset($arrRequest[$pagevar])?$arrRequest[$pagevar]:1;
        $this->redirect="page=tracking&action=list&{$pagevar}={$curpage}";
    }*/
    function delete()
    {
        $this->form->set_id($this->objNaanalRequest->getData('id'));
        $this->form->remove();
        $pagevar=ClsConfig::$PAGINATION_VAR;
        $curpage=isset($this->arrNaanalData[$pagevar])?$this->arrNaanalData[$pagevar]:1;
        $this->redirect="{$this->urlModuleParam}=tracking&{$this->urlActionParam}=list&{$pagevar}={$curpage}";
    }
    function preview() 
    {
        $this->form->loadObject($this->objNaanalRequest->getData('id'));
        return array('form'=>$this->form);
    } 
}
?>
